//
//  CommodityDetailsTableViewController.m
//  CenturyInterconnection
//
//  Created by 郭先生 on 16/4/7.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "CommodityDetailsTableViewController.h"
#import "SDCycleScrollView.h"
#import "RightMenuViewController.h"
#import "ReviewsViewController.h"
#import "InfoViewController.h"
#import "DownIconSheet.h"
#import "CommodityDetailsModel.h"
#import "RegisterViewController.h"
#import "ShoppingCarViewController.h"
#import "SDPhotoBrowser.h"
#import "HomePageViewController.h"
#import "XXNavigationController.h"
#import "WishListViewController.h"
#import "CurrencyConversionViewController.h"
#import "PrivacyStatementViewController.h"
#import "ContactUsViewController.h"
#import "JCAlertView.h"
#import "ShoppingCarViewController.h"

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

@interface CommodityDetailsTableViewController ()<UITableViewDataSource,UITableViewDelegate,SDCycleScrollViewDelegate,DownSheetDelegate,RightMenuViewControllerDelegate,SDPhotoBrowserDelegate>

@property (nonatomic,strong) NSArray * array;

@property (nonatomic,strong) NSArray * allTitleDatas;
@property (nonatomic,strong) NSArray * allIconDatas;


@property (nonatomic,strong) NSMutableArray * allImagesArray;       //图片
@property (nonatomic,strong) NSMutableArray * allLargeImagesArray;  //图片
@property (nonatomic,strong) NSMutableArray * allImagesViewArray;


@property (nonatomic,strong) NSString * sizeIdStr;
@property (nonatomic,strong) NSString * sizeStr;
@property (nonatomic,strong) NSString * optionIdStr;

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) RightMenuViewController *rightMenuViewController;
@property (nonatomic,strong) UIView*coverView1;

@property(nonatomic,strong)UILabel *messageLabel;
@property(nonatomic,assign)NSInteger messageCount;

@end

@implementation CommodityDetailsTableViewController

#pragma mark -
-(UITableView *)tableview{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,64, KScreenWidth, KScreenHeight-ACTUAL_HEIGHT(110)) style:UITableViewStyleGrouped];
        //设置代理为自己
        _tableView.delegate  =self;
        _tableView.dataSource=self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;
        _tableView.backgroundColor = [UIColor clearColor];
    }
    return _tableView;
}

//-(RightMenuViewController *)rightMenuViewController{
//    if (!_rightMenuViewController) {
//        _rightMenuViewController=[[RightMenuViewController alloc]init];
//        _rightMenuViewController.delegate=self;
//        _rightMenuViewController.view.frame=CGRectMake(KScreenWidth, 0, KScreenWidth-ACTUAL_WIDTH(200), KScreenHeight);
//    }
//    return _rightMenuViewController;
//}


// NSLog(测试);


#pragma mark - 获取数据
-(void)getDatas{
    
    self.allTitleDatas= @[@"PRODUCT INFO",
                          @"REVIEWS",
                          @"ADD TO WISHLIST"];
    
    self.allIconDatas=@[@"icon_info",
                        @"icon_reviews",
                        @"icon_add"];
    
    // http://viprunningonline.com/api/index.php?main_page=product_info&products_id=77
    
    NSString *urlStrr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    
    NSDictionary*paramss=@{@"main_page":@"product_info",
                           @"products_id":self.idStr};
    
    HttpManager*managerr=[[HttpManager alloc]init];
    [managerr getDataFromNetworkWithUrl:urlStrr parameters:paramss compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            
            self.productDetail = [[CommodityDetailsModel alloc] initWithShopDict:data[@"data"]];
            
            NSInteger cout = self.productDetail.addtional_images.count;
            for (int i=0; i<cout; i++) {
                [self.allImagesArray addObject:self.productDetail.addtional_images[i][@"image_medium"]];
                [self.allLargeImagesArray addObject:self.productDetail.addtional_images[i][@"image_large"]];
                
                UIImageView *imageView=[UIImageView new];
                imageView.tag=i;
                [self.allImagesViewArray addObject:imageView];
            }
            
            [self.tableView reloadData];
            
            
            if(self.productDetail.products_attrbutes.count > 0)
            {
                self.optionIdStr = self.productDetail.products_attrbutes[0][@"products_options_id"];
            }
            
            [self initSizeData];
        }
        
    }];
    
    // http://viprunningonline.com/api/index.php?main_page=shopping_cart
    NSString*urlStr1=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
    NSDictionary*params1=@{@"main_page":@"shopping_cart"};
    HttpManager*manager1=[[HttpManager alloc]init];
    [manager1 getDataFromNetworkWithUrl:urlStr1 parameters:params1 compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            self.messageCount=[data[@"data"][@"cart"] count];
            [self makeNaviButton];
        }
    }];
}


#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"Details";
    
    self.allImagesArray=[NSMutableArray array];
    self.allLargeImagesArray=[NSMutableArray array];
    self.allImagesViewArray=[NSMutableArray array];
    
    [self makeNaviButton];
    [self initSizeData];
    [self addButton];
    [self.view addSubview:self.tableview];
    [self lines];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self getDatas];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:[NSString stringWithFormat:@"DetailPage >>>>> %@",self.productDetail.products_name]];//("PageOne"为页面名称，可自定义)
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick beginLogPageView:[NSString stringWithFormat:@"DetailPage >>>>>> %@",self.productDetail.products_name]];
}
-(void)makeNaviButton{
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem  * barButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_back"]
                                                                    style:UIBarButtonItemStylePlain
                                                                   target:self
                                                                   action:@selector(comeBack)];
    self.navigationItem.leftBarButtonItem = barButton;
    
    
    
    
    
//    if (self.messageCount > 0) {
//        _messageLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(-15),ACTUAL_HEIGHT(5), ACTUAL_WIDTH(20), ACTUAL_HEIGHT(20))];
//        _messageLabel.backgroundColor=RGBACOLOR(206, 207, 208, 1);
//        _messageLabel.layer.cornerRadius = 10;
//        _messageLabel.layer.masksToBounds = YES;
//        //_messageLabel.text=@"1";
//        _messageLabel.text=[NSString stringWithFormat:@"%ld",(long)self.messageCount];
//        _messageLabel.textAlignment=1;
//        _messageLabel.textColor=[UIColor blackColor];
//        [_messageLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
//        [[SlideNavigationController sharedInstance].rightBarButtonItem.customView addSubview:_messageLabel];
//    }
}

#pragma mark - 返回事件
-(void)comeBack{

    if (self.isShoppingVCPush == YES) {
        ShoppingCarViewController * shoppingVC = [[ShoppingCarViewController alloc]init];
        [self.navigationController pushViewController:shoppingVC animated:NO];
    }
    else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

#pragma mark - tableView
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==1) {
        //product info
        NSString * priceStr = self.productDetail.products_price;
        NSString * describeStr = self.productDetail.products_description;
        NSString * modelStr = self.productDetail.products_model;
        NSString * titleStr = self.productDetail.products_name;
        NSDictionary *dict = @{@"index" : self.productDetail.products_name};
        [MobClick event:@"DetailPage_productInfoClick" attributes:dict];
        NSString * str = [NSString stringWithFormat:@"%@\nThe Model is:%@\n%@\n%@",priceStr,describeStr,modelStr,titleStr];
        
        [JCAlertView showOneButtonWithTitle:@"Product info" Message:str ButtonType:JCAlertViewButtonTypeCancel ButtonTitle:@"got it" Click:^{} ];
    
    }
    
    if (indexPath.row==2) {
        //reviews
        ReviewsViewController * rvc = [[ReviewsViewController alloc]init];
        rvc.productId=self.idStr;
        [self.navigationController pushViewController:rvc animated:NO];
    }
    
    if (indexPath.row==3) {
        //add to wishlist
        [self sharedView];
        
        
    }
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([indexPath indexAtPosition:1]==0) {
        return ACTUAL_HEIGHT(50);
    } else{
        return ACTUAL_HEIGHT(45);
    }
}

//indexPath行返回什么样子
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    
    if (indexPath.row==0) {
//        //选择尺寸
//        UILabel *sizelabel=[cell viewWithTag:01];
//        if (!sizelabel) {
//            sizelabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(10), ACTUAL_WIDTH(220), ACTUAL_HEIGHT(30))];
//            sizelabel.tag=01;
//            [cell addSubview:sizelabel];
//        }
////        sizelabel.backgroundColor=[UIColor yellowColor];
//        sizelabel.font=[UIFont systemFontOfSize:16];
//        if (self.sizeStr.length==0) {
//            sizelabel.text=@"SIZE:(Please select a size)";
//        }else{
//            sizelabel.text=[NSString stringWithFormat:@"SIZE:%@",self.sizeStr];
//        }

       
        
        //价格
        UILabel *moneyLabel=[cell viewWithTag:02];
        if (!moneyLabel) {
            moneyLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(10), KScreenWidth-ACTUAL_WIDTH(40), ACTUAL_HEIGHT(30))];
            moneyLabel.tag=02;
            [cell addSubview:moneyLabel];
        }
        moneyLabel.text= self.productDetail.products_price;
        moneyLabel.textAlignment=0;
        moneyLabel.textColor=[UIColor blackColor];
        moneyLabel.font=FONT_SYSTEM_36;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        
        NSString * urlStr;
        if (self.productDetail.addtional_images.count == 0) {
            urlStr = self.imgUrlStr;
            
        }else{
            urlStr = self.allImagesArray[0];
        }
        NSString * priceStr = self.productDetail.products_price;
        NSString * modelStr = self.productDetail.products_model;
        NSString * titleStr = self.productDetail.products_name;
        FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
        content.contentURL = [NSURL
                              URLWithString:urlStr];
        NSString * downloadStr = @"https://itunes.apple.com/us/app/id1145259011?ls=1&mt=8";
        content.contentDescription = [NSString stringWithFormat:@"%@,%@:%@\n Download Address:%@",priceStr,modelStr,titleStr,downloadStr];
        content.contentTitle = @"Shoes365";
        content.quote = @"Shoes365";
        FBSDKShareButton *shareButton = [[FBSDKShareButton alloc] init];
        shareButton.shareContent = content;
        [cell addSubview:shareButton];
        [shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-20);
            make.centerY.equalTo(cell.mas_centerY);
            
        }];
        
        
        
    }else if(indexPath.row == 4){
        
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = [NSString stringWithFormat:@"%@",[self.productDetail.products_name  uppercaseString]];
        cell.textLabel.font = FONT_SYSTEM_24;
        cell.textLabel.textColor = RGBACOLOR(153, 153, 153, 1);
        cell.textLabel.numberOfLines = 0;
        
    }else{
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //UIImageView
        UIImageView *imageView=[cell viewWithTag:03];
        if (!imageView) {
            imageView=[[UIImageView alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(15), ACTUAL_WIDTH(20), ACTUAL_HEIGHT(20))];
            imageView.tag=03;
            [cell addSubview:imageView];
        }
        [imageView setImage:[UIImage imageNamed:self.allIconDatas[indexPath.row-1]]];
        
        //UILabel
        UILabel *titleLabel=[cell viewWithTag:04];
        if (!titleLabel) {
           titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(60), ACTUAL_HEIGHT(10), ACTUAL_WIDTH(200), ACTUAL_HEIGHT(30))];
            titleLabel.tag=04;
            [cell addSubview:titleLabel];
        }
        titleLabel.font=FONT_SYSTEM_24;
        titleLabel.textColor = RGBACOLOR(152, 153, 153, 1);
        titleLabel.text=self.allTitleDatas[indexPath.row-1];
    }
    
//// =========== cell分割线 ===========
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]){
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return KScreenWidth;
    }else{
        return ACTUAL_HEIGHT(0.00001);
    }
}


-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section==0) {
        UIView *BGView=[[UIView alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(0), ACTUAL_HEIGHT(0), KScreenWidth, ACTUAL_HEIGHT(310))];
        
        if (self.productDetail.addtional_images.count == 0) {
            UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, KScreenWidth*0.15, KScreenWidth,KScreenWidth*0.7)];
            [imgView sd_setImageWithURL:[NSURL URLWithString:self.imgUrlStr] placeholderImage:nil];
            [BGView addSubview:imgView];
            
        }else{
            
            SDCycleScrollView* cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenWidth) imagesGroup:self.allImagesArray];
            cycleScrollView.delegate = self;
            cycleScrollView.autoScrollTimeInterval = 5.0;
            
            [BGView addSubview:cycleScrollView];
            
        }
        
        return BGView;
    }else{
        return nil;
    }
}


#pragma mark - 尺码
-(void)initSizeData{

    if(self.productDetail.products_attrbutes.count > 0 ){
        NSArray *array= self.productDetail.products_attrbutes[0][@"products_options_values"];
        
        MenuList1 = [NSMutableArray array];
        
        for (int i=0; i<array.count; i++) {
            
            DownSheetModel *Model= [[DownSheetModel alloc]init];
            Model.title= [NSString stringWithFormat:@"%@ (%@)",
                                                    array[i][@"products_options_values_name"],
                                                    array[i][@"options_values_price"]];
            [MenuList1 addObject:Model];
        }
    }
}

-(void)didSelectIndex:(NSInteger)index{
        self.sizeIdStr= self.productDetail.products_attrbutes[0][@"products_options_values"][index][@"products_options_values_id"];
        self.sizeStr=self.productDetail.products_attrbutes[0][@"products_options_values"][index][@"products_options_values_name"];
        [self jumpCartView];
    
    
//    [self.tableView reloadData];
}


#pragma mark - =============== cell分割线 ===============
-(void)lines{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]){
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]){
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

//#pragma mark =============== 分享弹出页面 ===============
//-(void)sharedView{
//    DownIconSheet *sheet = [[DownIconSheet alloc]initWithlist:MenuList height:0];
//    sheet.delegate = self;
//    [sheet showInView:nil];
//}

#pragma mark =============== 添加按钮 ===============
-(void)addButton{
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, ACTUAL_HEIGHT(623), KScreenWidth, ACTUAL_HEIGHT(45))];
    
    btn1.backgroundColor= [UIColor blackColor];
    
    [btn1 setTitleColor:[UIColor whiteColor] forState:0];

    [btn1 setTitle:@"ADD TO CART" forState:UIControlStateNormal];
    [btn1 setImage:[UIImage imageNamed:@"product_shopping"] forState:UIControlStateNormal];
    btn1.imageEdgeInsets = UIEdgeInsetsMake(12,100,12,250);
    btn1.titleLabel.font = FONT_SYSTEM_36;
    [btn1 addTarget:self action:@selector(jumpSizeView) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn1];
}

#pragma mark =============== 弹出尺码界面 ===============
-(void)jumpSizeView{
    NSDictionary *dict = @{@"index" : self.productDetail.products_name};
    [MobClick event:@"DetailPage_addToCartClick" attributes:dict];
    if (MenuList1.count > 0) {
        DownSheet *sheet = [[DownSheet alloc] initWithlist:MenuList1 height:0];
        sheet.delegate = self;
        [sheet showInView:nil];
    }else{
        [JRToast showWithText:@"no size！not sell"];
    }
   
}

#pragma mark =============== 跳转购物车 ===============
-(void)jumpCartView{
    
    if (self.sizeIdStr==nil) {
        [JRToast showWithText:@"Please select a size！"];
    }else{
        
        NSString *str=[NSString stringWithFormat:@"id[%@]",self.optionIdStr];

        // http://viprunningonline.com/api/index.php?main_page=cart_actions&act=add&products_id=77&cart_quantity=1
        NSString*aaa=@"main_page=cart_actions";
        NSString*urlStr=[NSString stringWithFormat:@"%@%@",HTTP_ADDRESS,aaa];


        NSDictionary*params=@{@"act":@"add",
                              @"products_id":self.idStr,
                              @"cart_quantity":@"1",
                              str:self.sizeIdStr,
                              @"zenid":[UserSession instance].cookie};
    HttpManager*manager=[[HttpManager alloc]init];

    [manager postDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            [JRToast showWithText:@"Add to cart success！"];
            [self GotoTheShoppingCart];
            
        }else{
            [JRToast showWithText:data[@"status_message"]];
        }
    }];

    }
}

-(void)GotoTheShoppingCart{
    NSDictionary *dict = @{@"index" : self.productDetail.products_name};
    [MobClick event:@"DetailPage_SizeClick" attributes:dict];
    ShoppingCarViewController *vc=[[ShoppingCarViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark 右侧边栏委托事件

-(void)delegaetForGotoRegister{
    //[self touchTap1];
    RegisterViewController *vc=[[RegisterViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)delegateForGotoShoppingCar{
    //[self touchTap1];
    ShoppingCarViewController *vc=[[ShoppingCarViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)delegateForGotoCancellation{
    //[self touchTap1];
    if ([UserSession instance].isLogin==NO) {
        [JRToast showWithText:@"You have not logged in！"];
    }else{
        UserSession*session=[UserSession instance];
        [session cleanUser];         //清空全局单例里的数据
        HomePageViewController*vc=[[HomePageViewController alloc]init];
        XXNavigationController*vcc=[[XXNavigationController alloc]initWithRootViewController:vc];
        [UIApplication sharedApplication].keyWindow.rootViewController=vcc;
        
        //http://viprunningonline.com/api/index.php? main_page=logoff
        NSString*urlStr=[NSString stringWithFormat:@"%@",HTTP_ADDRESS];
        NSDictionary*params=@{@"main_page":@"logoff"};
        HttpManager*manager=[[HttpManager alloc]init];
        
        [manager getDataFromNetworkWithUrl:urlStr parameters:params compliation:^(id data, NSError *error) {
            
        }];
    }
}

-(void)delegateForGotoWishList{
    //[self touchTap1];
    WishListViewController *vc=[[WishListViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)delegateForGotoCurrencyConversion{
    //[self touchTap1];
    CurrencyConversionViewController *vc=[CurrencyConversionViewController alloc];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)delegateForGotoPrivacyStatement{
    //[self touchTap1];
    PrivacyStatementViewController *vc=[[PrivacyStatementViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)delegateForGotoContactUs{
    //[self touchTap1];
    ContactUsViewController *vc=[[ContactUsViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    //NSLog(@" %ld ", index);
    
    SDPhotoBrowser * browser = [[SDPhotoBrowser alloc] init];
    browser.currentImageIndex = index;
    browser.sourceImagesContainerView = cycleScrollView;
    browser.imageCount = self.allLargeImagesArray.count;
    browser.delegate = self;
    [browser show];
    
}


#pragma mark - private actions

//- (void)tapImageView:(UITapGestureRecognizer *)tap
//{
//    UIView *imageView = tap.view;
//    SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
//    browser.currentImageIndex = imageView.tag;
//    browser.sourceImagesContainerView = self.view;
//    browser.imageCount = self.allLargeImagesArray.count;
//    browser.delegate = self;
//    [browser show];
//}

#pragma mark - SDPhotoBrowserDelegate

- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
{
    NSString *imageName = self.allLargeImagesArray[index];
    NSURL *url = [NSURL URLWithString:imageName];
    return url;
}

- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
    UIImageView *imageView = self.allImagesViewArray[index];
    return imageView.image;
}

#pragma mark 点击加入心愿单
-(void)sharedView{
    if ([UserSession instance].isLogin==NO) {
        [JRToast showWithText:@"Please login first！"];
    }else{
    // http://viprunningonline.com/api/index.php? main_page=products_list
        NSDictionary *dict = @{@"index" : self.productDetail.products_name};
        [MobClick event:@"DetailPage_addToWishlistClick" attributes:dict];
    NSString*urlStrr=[NSString stringWithFormat:@"%@main_page=wishlist_actions",HTTP_ADDRESS];
    NSDictionary*paramss=@{@"act":@"add",@"products_id":self.idStr,@"zenid":[UserSession instance].cookie};
    HttpManager*managerr=[[HttpManager alloc]init];
    
    [managerr postDataFromNetworkWithUrl:urlStrr parameters:paramss compliation:^(id data, NSError *error) {
        
        NSString*number=[NSString stringWithFormat:@"%@",data[@"status"]];
        
        if ([number isEqualToString:@"1"]) {
            [JRToast showWithText:@"Add a success！"];
        }else{
            [JRToast showWithText:@"Add failure!"];
        }
    }];
    }
}




@end
